package com.vehicle.biz.core.support;

import com.github.pagehelper.util.StringUtil;
import com.vehicle.biz.core.support.impl.CommonSupport;
import com.vehicle.biz.core.support.impl.TransportSupport;
import com.vehicle.enums.VehicleTypeEnum;
import com.vehicle.exception.VehicleAccessException;
import jakarta.annotation.Resource;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PlateDetectSupportFactory {
    @Resource
    private List<PlateDetectSupport> supportList;

    @Resource
    private ApplicationContext applicationContext;

    public PlateDetectSupport getSupport(String vehicleType) {
        if (StringUtil.isEmpty(vehicleType)) {
            return applicationContext.getBean("commonSupport", CommonSupport.class);
        }

//        if (VehicleTypeEnum.COMMON.name().equals(vehicleType)) {
//            return applicationContext.getBean("commonSupport", CommonSupport.class);
//        }
//
//        if (VehicleTypeEnum.TRANSPORT.name().equals(vehicleType)) {
//            return applicationContext.getBean("transportSupport", TransportSupport.class);
//        }

        for (PlateDetectSupport support : supportList) {
            if (support.getSupportName().equals(vehicleType)) {
                return support;
            }
        }

        throw VehicleAccessException.IMPL_NOT_EXIST.newInstance("can not find PlateDetectSupport");
    }
}
